function banner ( name )
{
	banner.instances [ name ] = this;

	this.name   = name;
	this.div_id = null;

	this._images = [];
	this._items = {};
	this._curr_img = 0;
	this._curr_pos = 0;

	// Offset correction
	this.offset_correction = 0;

	// Height of banner (in pixels)
	this.banner_height = 190;

	this.show_timeout = 1000;
	this.scroll_timeout = 50;
	this.scroll_step = 1;

	this.events = {
				"click" : null,
				"hover" : null,
				"out"   : null,
				"stop"  : null,
				"resume" : null
			};

	this._clear_show = null;
	this._clear_scroll = null;
	this._is_running = false;

	this.show_navigation = true;

	this.render = function ( div_id )
	{
		if ( div_id ) this.div_id = div_id;

		var s = '<div class="banner_box"><div class="banner_base"><div class="banner_image_roll" id="image_roll">' +
			'<div id="roll1" class="banner_image"></div>' + 
			'<div id="roll2" class="banner_image"></div>' +
			'</div></div>';
		var e;

		s += '<div class="banner_mask" onmouseover="banner.stop(\'' + this.name + '\')" onmouseout="banner.resume(\'' + this.name + '\')" onclick="banner._clk(event,\'' + this.name + '\')"></div>';

		if ( this.show_navigation ) s += this._mk_navigation ();

		s += '</div>';

		e = document.getElementById ( this.div_id );
		if ( ! e )  return;

		e.innerHTML = s;
		this._start_roll ();
	};

	this._mk_navigation = function ()
	{
		var t = 0, l = this._images.length;
		var s = '';

		s = '<div class="banner_navi"><a href="javascript:banner.go(\'' + this.name + '\',0)">&lt;&lt;</a>';
		for ( t = 1; t < ( l - 1 ); t ++ )
			s += '&nbsp;&nbsp;<a href="javascript:banner.go(\'' + this.name + '\',' + t + ')">' + ( t + 1 ) + '</a>';

		s += '&nbsp;&nbsp;<a href="javascript:banner.go(\'' + this.name + '\',' + ( l - 1 ) + ')">&gt;&gt;</a>';

		return s + '</div>';
	};

	this._start_roll = function ()
	{
		var self = this;

		this.stop ();

		this._is_running = true;

		this._items [ 0 ] = ( this._curr_img % this._images.length );
		this._items [ 1 ] = ( ( this._items [ 0 ] + 1 ) % this._images.length );

		document.getElementById ( "roll1" ).style.backgroundImage = "url(" + this._images [ this._items [ 0 ] ] + ")";
		document.getElementById ( "roll2" ).style.backgroundImage = "url(" + this._images [ this._items [ 1 ] ] + ")";
		document.getElementById ( "image_roll" ).style.top = "0px";

		this._clear_show = setTimeout ( function () { self._rotate ( 0 ); }, this.show_timeout );
	};

	this._rotate = function ( pos )
	{
		var self = this;
		var dest = document.getElementById ( "image_roll" );

		if ( ! dest )
		{
			this.stop ();
			return;
		}

		if ( ! this._is_running ) return;

		this._clear_show = null;

		dest.style.top = pos + "px";


		if ( Math.abs ( pos ) < this.banner_height )
		{
			this._clear_scroll = setTimeout ( function () { self._rotate ( pos - self.scroll_step ); }, this.scroll_timeout );
			this._curr_pos = pos;
		} else {
			this._curr_pos = 0;
			this._curr_img += 1;
			this._start_roll ();
		}
		
	};

	this.go = function ( pos )
	{
		this.stop ();
		this._curr_img = pos;
		this._curr_pos = 0;
		this._start_roll ();
	};

	this.resume = function ()
	{
		if ( this.events [ 'resume' ] ) this.events [ 'resume' ] ( this );

		this._is_running = true;
		this._rotate ( this._curr_pos );
	};

	this.stop = function ()
	{
		if ( this.events [ 'stop' ] ) this.events [ 'stop' ] ( this );

		if ( this._clear_show ) clearTimeout ( this._clear_show );
		if ( this._clear_scroll ) clearTimeout ( this._clear_scroll );

		this._is_running = false;
	};

	this.click = function ( div_pos )
	{
		var item_pos;

		this.stop ();
	
		item_pos = this._items [ div_pos ];

		// console.debug ( "Banner clicked: ", item_pos );
		
		if ( this.events [ 'click' ] ) this.events [ 'click' ] ( this, item_pos );
	};

	this.add_images = function ()
	{
		var t, l = arguments.length;
		for ( t = 0; t < l; t ++ )
			this._images.push ( arguments [ t ] );
	};

}

banner.instances = {};

banner.get_instance = function ( name )
{
};

banner.stop = function ( name )
{
	var b = banner.instances [ name ];
	if ( b ) b.stop ();
};

banner.resume = function ( name )
{
	var b = banner.instances [ name ];
	if ( b ) b.resume ();
};

banner.go = function ( name, pos )
{
	var b = banner.instances [ name ];
	if ( b ) b.go ( pos );
};

banner.click = function ( name, div_pos )
{
	var b = banner.instances [ name ];

	if ( b ) b.click ( div_pos );
};

banner._clk =  function ( e, name )
{
	var b = banner.instances [ name ]
	var y;
	if ( ! b ) return;

	e = ( e ? e : window.event );

	y = e.clientY - b.offset_correction;

	// console.debug ( y + " - " + b._curr_pos + " - " + ( b.banner_height + b._curr_pos - y ) );
	b.click ( ( ( b.banner_height + b._curr_pos - y ) > 0 ? 0 : 1 ) );
};
